package src.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import src.model.DbContext;
import src.view.runProject;

public class moviesMain implements Runnable {

	private DbContext database;
	private runProject project;

	public void StartApp() {
		SwingUtilities.invokeLater(this);
		this.database = DbContext.getInstance();
	}	

	@Override
	public void run() {
		project = new runProject();
		project.makeVisible(true);
		project.biletAlAction(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				project.makeVisible(false);
				project.ChooseSeats(project.SaloonName());
				project.updateComboList(database.getSeansRES().getAll());
				project.selectComboBox(database.getMoviesRES().findById(project.movieindex()).getSaloons());
			}
		});
		project.updateListModel(database.getMoviesRES().getAll());
		project.listClick(new ListSelectionListener() {
			
			@Override
			public void valueChanged(ListSelectionEvent e) {
				project.movieindex();
				project.updateLabels(database.getMoviesRES());
				
			}
		});
	}
}
